#include<iostream>
#include<unordered_map>
#include<queue>
using namespace std;
#define x first
#define y second
typedef pair<int, int> PII;
const int N = 1e5 + 10, M = N * 5;
int n, m, s, t;
int st[N];
int h[N], e[M], ne[M], idx, w[M];
int dis[N];
int flag1 = 0, flag = 0;
unordered_map<int, int>mp;
void add(int a, int b, int c)
{
	e[idx] = b;
	w[idx] = c;
	ne[idx] = h[a];
	h[a] = idx++;
}
int dij()
{
	priority_queue<PII, vector<PII>, greater<PII>>q;
	memset(dis, 0x3f, sizeof(dis));
	dis[s] = 0;
	q.push({ 0,s });
	while (q.size()) {
		PII t = q.top();
		q.pop();
		int ver = t.y;
		int distance = t.x;
		if (st[ver])continue;
		st[ver] = 1;
		for (int i = h[ver]; ~i; i = ne[i]) {
			int j = e[i];
			if (mp[j] == 1) {
				if (dis[j] > distance + w[i]) {
					dis[j] = distance + w[i];
					q.push({ dis[j],j });
				}
			}
			
		}
	}
	if (dis[t] > 0x3f3f3f3f / 2)return -1;
	return dis[t];
}
int main()
{
	cin >> n >> m >> s >> t;
	memset(h, -1, sizeof(h));
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		mp[i] = x;
	}
	while (m--) {
		int a, b, c;
		cin >> a >> b >> c;
		add(a, b, c);
	}
	cout << dij() << endl;
	return 0;
}